<?php
namespace Book\Controller;

use Think\Controller;

class DashboardController extends Controller
{
    public function index()
    {
        //文档列表
        $map['namespace'] = session('username');
        $page_list        = D('Book')->where($map)->select();
        $this->assign('page_list', $page_list);
        $this->display();
    }

    function new () {
        if (IS_POST) {
            //如果报错
            /*{
            "name": "文档标识不能为空",
            "title": "文档名称不能为空"
            }*/
            $info = I('post.');
            D('Book')->new($info);
            //成功跳转
            $return['redirect'] = "/book/{$info['namespace']}/{$info['name']}/dashboard";
            $this->ajaxReturn($return);
        } else {
            $this->assign('namespace', session('username'));
            $this->display();
        }
    }
}
